package com.quickstart.admin.controller;

import com.quickstart.admin.service.AdminService;
import com.quickstart.entity.AdminEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author:wesley
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;


    @RequestMapping(value = "/login")
    @ResponseBody
    public Map<String,Object> login(String name, String pass, HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        AdminEntity adminEntity = adminService.login(name, pass);
        if (adminEntity!= null) {
            request.getSession().setAttribute("admin",adminEntity);
            map.put("tag",true);
        } else {
            map.put("tag",false);
        }
        return map;
    }



}
